home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / PredatorPrey / PredatorPreyData.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-22  |  7.7 KB  |  386 lines  |  [TEXT/KAHL]

  1. /* C14CalculatorData.c -- application-specific data management */
  2.  
  3. /*    look at this, check for nil?    */
  4.  
  5. /* This module contains data structures to access the data in your */
  6. /* document's file(s). The purpose is to isolate the details of the */
  7. /* data representation into this module and to provide accessor */
  8. /* functions for reading/writing logical pieces of the data. */
  9. /* For your application, you will probably rewrite most of this. */
  10. /* This module will not be regenerated by AppMaker unless you delete it. */
  11.  
  12. #include <Types.h>
  13. #include <Quickdraw.h>
  14. #include <Controls.h>
  15. #include <Events.h>
  16. /*#include <Lists.h>*/
  17. #include <Menus.h>
  18. #include <TextEdit.h>
  19. #include "Globals.h"
  20. #include "Miscellany.h"
  21.  
  22. #include "PredatorPreyData.h"
  23. #ifndef __C14__
  24. #include    "PredatorPrey.h" 
  25. #endif
  26. #include "calc_dipshit.h"
  27. #include "Cursors.h"
  28. #include    "ParseDataString.h"
  29.  
  30.  
  31. /* Define additional "private" data structures. */
  32.  
  33. #define    yesNoCancelDLOG    132
  34. #define    errorDLOG        256
  35. #define MaxPoints        2500
  36.  
  37.         SFReply                sfInfo;
  38. extern    TEHandle            theTEHndl;
  39.         Handle                theTextHndl;    /*extern*/
  40. extern    CharsHandle            theCharsHndl;
  41. extern    CharsHandle            theChars2Hndl;
  42. extern    short                gWindowState;
  43. extern    short                gMatWin;    
  44. extern    long                gState;
  45. extern    double                aaa[MaxPoints][3];
  46.  
  47. pascal     void    HiliteDefaultButton(DialogPtr    theDPtr, short    whichItem);
  48. char            tempString[256];
  49.  
  50. struct    cNode;
  51. struct    dData;
  52. struct    dNode;
  53.  
  54.  
  55. struct    Root
  56. {
  57.     struct    cNode    *cNext;
  58. };
  59.  
  60. struct    Root    *theRootPtr,    *rCurrentPtr;
  61.  
  62. struct    cNode
  63. {
  64.     struct        cNode    *cNext;
  65.     struct        dNode    *dNext;
  66.     short        cCount;
  67.     double_t    runConst;
  68.     
  69. };
  70.  
  71. struct    cNode    *cCurrentPtr,    *cTempPtr;
  72.  
  73. struct    dNode
  74. {
  75.     struct        dNode    *dNext;
  76.     short        dCount;
  77.     short        dataCount;
  78.     double_t    runData;
  79.     //struct    dData    *daNext;
  80. };
  81.  
  82. struct    dNode    *dCurrentPtr,    *dTempPtr;
  83.  
  84.  
  85.  
  86. typedef struct {
  87.         short        data;
  88. } MoreStuff;
  89.  
  90.         void        CenterSWindow        (WindowPtr    wPtr);
  91. extern    void        ErrorShow            (short    which);
  92. extern    void    ResultDeParse        (    double_t    resultIn,
  93.                                         short        *fxLen,
  94.                                         short        *flLen
  95.                                     );
  96.  
  97.  
  98. void    C14Data_seg() {}        /*  for reference in "UnloadSeg()" calls    */
  99.  
  100. /*----------*/
  101. void    AddStuff    (YourStuff        *stuff)
  102. {
  103. #pragma unused (stuff) 
  104.   
  105. } /* AddStuff */
  106.  
  107. /*----------*/
  108. Boolean  GetStuff    (void)
  109. {
  110.     return (false);
  111. } /* GetStuff */
  112.  
  113.  
  114. /*----------*/
  115. void    DeleteStuff    (void)
  116. {
  117. } /* DeleteStuff */
  118.  
  119. void    InitMapData        (Str255 *fName, short refNum, short qRefNum)
  120. /*                                    ^            ^                ^                                */
  121. /*                                    |            |                |                                */
  122. /*                                    |            |                *----    file reference number    */
  123. /*                                    |            *--    working directory of current system folder    */
  124. /*                                    *----    data filename                                        */
  125. {
  126.     short    i,j;
  127.     StringHandle dataFileName;
  128.     
  129.     map.mem2name[0] = 6;
  130.     map.mem2name[1] = 'i';
  131.     map.mem2name[2] = 'k';
  132.     map.mem2name[3] = 'a';
  133.     map.mem2name[4] = 'b';
  134.     map.mem2name[5] = 'a';
  135.     map.mem2name[6] = 's';
  136.     map.mem3name[0] = 28;
  137.     map.mem4name[0] = 28;        /*PtrToHand(&(*fName),dataFileName,sizeof(fName));*/
  138.     dataFileName = NewString( *fName );
  139.     BlockMove(*dataFileName,*cur->qFilename,GetHandleSize((Handle) dataFileName));
  140.     cur->qFileNum = qRefNum;
  141.     DumbShit(2);    
  142. }
  143.  
  144. /*----------*/
  145. void    InitAppData        (void)
  146. {
  147. } /* InitAppData */
  148.  
  149. /*----------*/
  150. void    DisposeAppData    (void)
  151. {
  152. } /* DisposeAppData */
  153.  
  154. /*----------*/
  155. Boolean    OpenAppFile        (short        vRefNum,
  156.                          Str255        fName,
  157.                          short        *fRefNum)
  158. {
  159.     Boolean            okay;
  160.  
  161.     okay = CheckOS (FSOpen (fName, vRefNum, fRefNum));
  162.     return (okay);
  163. } /* OpenAppFile */
  164.  
  165. /*----------*/
  166. void    CloseAppFile    (short        fRefNum)
  167. {
  168.     Boolean            okay;
  169.  
  170.     if (fRefNum != 0) {        /* could be 0 if closing new document */
  171.         okay = CheckOS (FSClose (fRefNum));
  172.     }
  173. } /* CloseAppFile */
  174.  
  175. /*----------*/
  176. void    ReadAppFile     (short        fRefNum)
  177. {
  178.     /*#pragma unused (fRefNum)*/ 
  179.     OSErr         error;
  180.     long        fcount;
  181.     
  182.     fcount = sizeof(frog);
  183.     error = SetFPos(fRefNum,1,0);
  184.     error = FSRead(fRefNum,&fcount,&frog);
  185.     
  186.     InitAppData ();
  187. } /* ReadAppFile */
  188.  
  189.  
  190. void    ErrorAlert(char    *p0)    /* is pZERO    */
  191. {
  192. GrafPtr            oldPort;
  193. DialogPtr        theDPtr,tempDPtr;
  194. short            itemHit, type;
  195. Handle            theItem;
  196. Rect            theRect;
  197. EventRecord        theEvent;
  198. /*char            p1;*/
  199.  
  200.     /*Str255    pZero;*/
  201.     short    i;
  202.  
  203.     GetPort(&oldPort);
  204.     
  205.     InitCursor();
  206.     
  207.     if (!(theDPtr = GetNewDialog(errorDLOG, NULL,(WindowPtr) -1L)))
  208.     {
  209.         SysBeep(1);
  210.         ExitToShell();
  211.     }
  212.     
  213.     SetPort(theDPtr);
  214.     
  215.     CenterSWindow(theDPtr);
  216.     ShowWindow(theDPtr);
  217.     
  218.     ((DialogPeek) theDPtr)->aDefItem = 1;
  219.     
  220.     GetDItem(theDPtr, 3, &type, &theItem, &theRect);
  221.     SetDItem(theDPtr, 3, type, (Handle)HiliteDefaultButton, &theRect);
  222.     
  223.     GetDItem(theDPtr, 2, &type, &theItem, &theRect);
  224.     
  225.     /**strcpy(*p1,*p0);*/
  226.     CtoPstr(p0);
  227.     SetIText(theItem, (ConstStr255Param)p0);
  228.     /*PtoCstr(p0);*/
  229.     
  230.     while (!GetNextEvent(updateMask,&theEvent));
  231.     
  232.     if (theEvent.message == (long) theDPtr)
  233.         DialogSelect(&theEvent,&tempDPtr,&itemHit);
  234.     
  235.     SysBeep(1);
  236.     
  237.     do 
  238.     {
  239.         itemHit = 0;
  240.         
  241.         while (!GetNextEvent(everyEvent,&theEvent));
  242.         
  243.         if (theEvent.what==keyDown || theEvent.what==autoKey)
  244.         {
  245.             if ((theEvent.message & charCodeMask)=='\r' || (theEvent.message & charCodeMask)==0x03)
  246.                 itemHit = ((DialogPeek) theDPtr)->aDefItem;
  247.             else
  248.                 SysBeep(1);
  249.         }
  250.         
  251.         else
  252.         {
  253.             tempDPtr = (DialogPtr) 0L;
  254.             
  255.             if (!IsDialogEvent(&theEvent) || !DialogSelect(&theEvent,&tempDPtr,&itemHit) || tempDPtr!=theDPtr)
  256.                 itemHit = 0;
  257.         }
  258.         
  259.     } while (itemHit!=1);
  260.     
  261.     DisposDialog(theDPtr);
  262.     SetPort(oldPort);
  263. }
  264.  
  265.  
  266.  
  267. /*----------*/
  268. void    CenterSWindow(WindowPtr    wPtr)
  269. {
  270. int        screenWidth,screenHeight,windowWidth,windowHeight,left,top;
  271.  
  272.     if (wPtr == 0L)
  273.         return;
  274.     
  275.     screenWidth = qd.screenBits.bounds.right - qd.screenBits.bounds.left;
  276.     screenHeight = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top - 20;
  277.     windowWidth = wPtr->portRect.right - wPtr->portRect.left;
  278.     windowHeight = wPtr->portRect.bottom - wPtr->portRect.top;
  279.     
  280.     left = qd.screenBits.bounds.left + (screenWidth - windowWidth)/2;
  281.     top = qd.screenBits.bounds.top + 20 + (screenHeight - windowHeight)/2;
  282.     
  283.     if (left < 0)
  284.         left = 0;
  285.     
  286.     if (top < 20)
  287.         top = 20;
  288.     
  289.     MoveWindow(wPtr,left,top,FALSE);
  290. }
  291.  
  292.  
  293. /*----------*/
  294. void    WriteAppFile    (short    type,    short        fRefNum)
  295. {
  296.     /*#pragma unused (fRefNum)*/
  297.     OSErr         error;
  298.     long        count,fcount,mcount;
  299.     
  300.     count = sizeof(map);
  301.     fcount = sizeof(frog);
  302.     //mcount = sizeof(aaa[][3]);    /*    frog for now    */
  303.     
  304.     error = SetFPos(fRefNum,1,0);
  305.     
  306.     switch(type)
  307.     {
  308.         case 0:
  309.             error = FSWrite(fRefNum,&count,&map);
  310.             break;
  311.         case 1:
  312.             error = FSWrite(fRefNum,&fcount,&frog);
  313.             break;
  314.     //    case 2:
  315.     //        error = FSWrite(fRefNum,&mcount,&log);
  316.     //        break;
  317.     }
  318.       error = FlushVol(NIL,cur->volNum);
  319. } /* WriteAppFile */
  320.  
  321. /* AMTstShrData */
  322.  
  323. pascal void HiliteDefaultButton(DialogPtr theDPtr,short whichItem)
  324. {
  325. short        type;
  326. Handle        theItem;
  327. Rect        theRect;
  328.  
  329.     GetDItem(theDPtr, ((DialogPeek) theDPtr)->aDefItem, &type, &theItem, &theRect);
  330.     PenNormal();
  331.     PenSize(3,3);
  332.     InsetRect(&theRect,-4,-4);
  333.     FrameRoundRect(&theRect,16,16);
  334.     PenSize(1,1);
  335. }
  336.  
  337.  
  338. short    YesNoCancel(char    *thePrompt,short    theDefault)
  339. {
  340. DialogPtr        theDPtr,tempDPtr;
  341. short            itemHit, type;
  342. Handle            theItem;
  343. Rect            tempRect;
  344. GrafPtr            oldPort;
  345. char            tempString[256];
  346. EventRecord        theEvent;
  347.  
  348.     GetPort(&oldPort);
  349.     
  350.     InitCursor();
  351.     
  352.     theDPtr = GetNewDialog(yesNoCancelDLOG, 0L,(WindowPtr) -1L);
  353.     
  354.     CenterSWindow(theDPtr);
  355.     ShowWindow(theDPtr);
  356.     
  357.     SetPort(theDPtr);
  358.     
  359.     ((DialogPeek) theDPtr)->aDefItem = theDefault;
  360.     
  361.     GetDItem(theDPtr, 4, &type, &theItem, &tempRect);
  362.     SetDItem(theDPtr, 4, type, (Handle)HiliteDefaultButton, &tempRect);
  363.     
  364.     /*strcpy(tempString,thePrompt);*/
  365.     CtoPstr(tempString);
  366.     GetDItem(theDPtr, 5, &type, &theItem, &tempRect);
  367.     SetIText(theItem, (ConstStr255Param)tempString);
  368.     
  369.     if (GetNextEvent(updateMask,&theEvent) && theEvent.message == (long) theDPtr)
  370.         DialogSelect(&theEvent,&tempDPtr,&itemHit);
  371.     
  372.     SysBeep(1);
  373.     
  374.     do 
  375.     {
  376.         ModalDialog(0L,&itemHit);
  377.         
  378.     } while (!(itemHit>=1 && itemHit<=3));
  379.     
  380.     DisposDialog(theDPtr);
  381.     SetPort(oldPort);
  382.     
  383.     return(itemHit);
  384. }
  385.  
  386.